package dp_algorithm.leetcode.easy;

/**
 * @author bruin_du
 * @description 连续子数组的最大和
 * @date 2022/5/24 15:49
 **/
public class Offer42_MaxSubArray {
    public int maxSubArray(int[] nums) {
        int cur = nums[0],max = nums[0];
        for (int i = 1; i < nums.length; i++) {
            cur = Math.max(cur,cur + nums[i]);
            if(cur > max) max = cur;
        }
        return max;
    }
}
